***************
* This script performs the regression analysis on the recruiter click data
* Author: Daniel Kopp
***************	

	clear
	clear matrix
	clear mata
	set more off	
	set maxvar 8000
	
	* We define the following globals before loading the data since this is much faster
	preserve
	import excel "Help_files\interactvar.xlsx", clear firstrow
	quietly ds
	global interactvar = r(varlist)
	restore
	
	preserve
	import excel "Help_files\interactgender.xlsx", clear firstrow
	quietly ds
	global interactgender = r(varlist)
	restore

	preserve
	import excel "Help_files\interactethnicity.xlsx", clear firstrow
	quietly ds
	global interactethnicity = r(varlist)
	restore	
	
	* Add global with all lasso-selected covariates
	preserve	
	import delimited using "Misc_files\union_varnames_biglasso_workvolume_det_new.csv", clear varnames(1)
	keep x
	local biglasso_workvolume
	local obs = _N
	disp "`obs'"
	forvalues y = 1/`obs' { 
			local tempname = x[`y'] 
			local biglasso_workvolume : list biglasso_workvolume | tempname 
	} 
	global biglasso_workvolume "`biglasso_workvolume'"
	restore
		
	* Add global with all lasso-selected covariates for the gender regression
	preserve	
	import delimited using "Misc_files\varnames_biglasso_workvolume_geschlecht.csv", clear varnames(1)
	keep x
	local gender_interact
	local obs = _N
	disp "`obs'"
	forvalues y = 1/`obs' { 
			local tempname = x[`y'] 
			local gender_interact : list gender_interact | tempname 
	} 
	global gender_interact "`gender_interact'"
	restore
		
	use "data_processed\with_interactions_compr_all_full.dta"
	
	* Gen relative rank:
	gen rel_rank = rank/n_results
	gen rel_rank_sq = rel_rank^2
	gen rel_rank_3  = rel_rank^3
	
	* Gen cat. var. for rel. rank: 
	gen 	rel_rank_cat = 1 if inrange(rel_rank,0.0001,0.100001)
	replace rel_rank_cat = 2 if inrange(rel_rank,0.1001,0.200001)
	replace rel_rank_cat = 3 if inrange(rel_rank,0.2001,0.300001)
	replace rel_rank_cat = 4 if inrange(rel_rank,0.3001,0.400001)
	replace rel_rank_cat = 5 if inrange(rel_rank,0.4001,0.500001)
	replace rel_rank_cat = 6 if inrange(rel_rank,0.5001,0.600001)
	replace rel_rank_cat = 7 if inrange(rel_rank,0.6001,0.700001)
	replace rel_rank_cat = 8 if inrange(rel_rank,0.7001,0.800001)
	replace rel_rank_cat = 9 if inrange(rel_rank,0.8001,0.900001)
	replace rel_rank_cat = 10 if inrange(rel_rank,0.9001,100001)		
		
	* Gen dummies for rel_rank_cat
	local val_label : value label rel_rank_cat
	flevelsof rel_rank_cat, local(levels)
	foreach i of local levels {
	gen 	byte rel_rank_cat`i' = rel_rank_cat==`i'
	}	
	global rel_rank_cat "rel_rank_cat1 rel_rank_cat2 rel_rank_cat3 rel_rank_cat4 rel_rank_cat5 rel_rank_cat6 rel_rank_cat7 rel_rank_cat8 rel_rank_cat9 rel_rank_cat10"
	di "$rel_rank_cat"
	
	* Gen dummies for rank
	local rank ""
	local val_label : value label rank
	flevelsof rank, local(levels)
	foreach i of local levels {
	gen 	byte rank`i' = rank==`i'
	local varname "rank`i'"
	local rank: list rank | varname
	}
	global rank "`rank'"
	di "$rank"

	****************************
	* Define Globals
	****************************

	global skills_dummy_full    "has_skills sk_det_lang0 sk_det_lang1 sk_det_lang2 sk_det_lang3 sk_det_lang4 sk_det_lang_m  sk_exp  sk_education   sk_educ_tert  sk_educ_lehre  sk_educ_weiter sk_softskills sk_it_gen sk_it_deep sk_machines sk_leadership sk_language sk_lgerman sk_lfrench sk_litalian sk_lenglish sk_lchgerman sk_exp_dur_c0 sk_exp_dur_c1 sk_exp_dur_c2 sk_exp_dur_c3 sk_exp_dur_c4 sk_exp_dur_c_m sk_lsoutheuro sk_lother sk_lmiddleeast sk_lbalkan sk_lcentreast sk_lasia skill_country_region1_general skill_country_region2_general skill_country_region3_general skill_country_region4_general skill_country_region5_general skill_country_region6_general skill_country_region8_general skill_country_region9_general" 
	global lang_dummy_full 	"l_German l_CH_German l_English l_French  l_Italian l_northwest	l_southeuro l_centreast l_Balkan l_middleeast l_Asia l_Other l_missing"
	* Without geschlecht	workvolume_c1 workvolume_c2 workvolume_c3 workvolume_c_m
	global other_dummy "erfa_s0 erfa_s1 erfa_s2 erfa_s3 erfa_s_m mobility_cat0 mobility_cat1 mobility_cat2 mobility_cat3 mobility_cat4 mobility_cat_m 	limcontract0 limcontract1 limcontract99 verfuegbar0 verfuegbar1 verfuegbar99 no_searchvar no_diff_prof_m 	zuletzt_s abschluss_s0 abschluss_s1 abschluss_s2 abschluss_s3 abschluss_s_m gesch_kontakt Sonn_Feiertag Schichtarbeit Nachtarbeit Heimarbeit Lehre fuehrer_kat0 fuehrer_kat1 fuehrer_kat2 fuehrer_kat3 fuehrer_kat4 fuehrer_kat5 fuehrer_kat6 fuehrer_kat_m education_isced_1 education_isced_2 education_isced_3 education_isced_6 education_isced_7 education_isced_8 education_isced_999 prof_length_1 prof_length_2 prof_length_3 prof_length_4 prof_length_99 user_logged_in"
	global kanton "kanton1 kanton2 kanton3 kanton4 kanton5 kanton6 kanton7 kanton8 kanton9 kanton10 kanton11 kanton12 kanton13 kanton14 kanton15 kanton16 kanton17 kanton18 kanton19 kanton20 kanton21 kanton22 kanton23 kanton24 kanton25 kanton26"
	global lang_region "lang_region1 lang_region2 lang_region3 lang_region4"
	global other_contin " sk_est_n_word no_diff_prof prof_exp_tot"
	global occup_dummy "bn2000_1_s1 bn2000_1_s2 bn2000_1_s3 bn2000_1_s4 bn2000_1_s5 bn2000_1_s6 bn2000_1_s7 bn2000_1_s8 bn2000_1_s9"
	global squared "sk_est_n_word_2 no_diff_prof_2 prof_exp_tot_2"
	global nation_name_kat "nation_kat0 nation_kat1 nation_kat2 nation_kat3 nation_kat4 nation_kat5 nation_kat6 nation_kat8 nation_kat9 nation_kat_m name_kat0 name_kat1 name_kat2 name_kat3 name_kat4 name_kat5 name_kat6 name_kat7 name_kat8 name_kat_m"
	
	* Keep only interactions in the biglasso-global since we want to keep the other variables anyway in the regression
	local biglasso_workvolume $biglasso_workvolume
	local subtract $nation_name_kat geschlecht $other_dummy $lang_dummy_full $skills_dummy_full $kanton $occup_dummy $other_contin $squared
	local biglasso_workvolume: list biglasso_workvolume - subtract
	global biglasso_workvolume `biglasso_workvolume'
	di "$biglasso_workvolume"
	local words: disp wordcount(" $biglasso_workvolume ")
	disp "`words'" 	

	* We keep only the interactions selected by the lasso variable selection
	local drop_interactions $interactvar $interactethnicity $interactgender
	local subtract $biglasso_workvolume
	local drop_interactions: list drop_interactions - subtract
	global drop_interactions `drop_interactions'
	drop $drop_interactions	
	
	****************************
	* Sample restriction
	****************************

	* Sample restrictions
	run "Help_files\sample_restrictions_parttime.do"
	
	
	****************************
	* Gen new var and dummy vars
	****************************	
	
	gen base1 = 0
	gen base2 = 0
	gen base3 = 0
	global base_cat "base1 base2 base3"
	
	local val_label : value label education_isced
	levelsof education_isced, local(levels)
	foreach i of local levels {
	gen byte	education_isced_`i' = education_isced==`i'
	replace  	education_isced_`i' =. if education_isced==.
	local lab_`i' : label `val_label' `i'
	label var education_isced_`i' " `lab_`i'' "
	}	
		
	* Detailed workvolume categories
	gen 	workvolume_det_cat=0 if workvolume==100
	replace workvolume_det_cat=1 if inrange(workvolume,90,99)
	replace workvolume_det_cat=2 if inrange(workvolume,80,89)
	replace workvolume_det_cat=3 if inrange(workvolume,70,79)
	replace workvolume_det_cat=4 if inrange(workvolume,60,69)
	replace workvolume_det_cat=5 if inrange(workvolume,50,59)
	replace	workvolume_det_cat=6 if workvolume<50
	count if workvolume_det_cat==.		// 0
		
	* Gen dummies for workvolume_det_cat categories
	flevelsof workvolume_det_cat, local(levels)
	foreach i of local levels {
	gen 	byte workvolume_det_cat`i' = workvolume_det_cat==`i'
	replace      workvolume_det_cat`i' = . if workvolume_det_cat==.			
	}	
	
	global workvolume_det_cat "workvolume_det_cat0 workvolume_det_cat1 workvolume_det_cat2 workvolume_det_cat3 workvolume_det_cat4 workvolume_det_cat5 workvolume_det_cat6 "

	* Interactions between workvolume and gender
	local workvolume_gender ""
	foreach temp1 in $workvolume_det_cat {
		gen byte `temp1'Xgeschlecht = `temp1'*geschlecht 
		local tempname = " `temp1'Xgeschlecht " 
		local workvolume_gender : list workvolume_gender | tempname
		
	}
	global workvolume_gender "`workvolume_gender'"
			
	* With 4 categories:
	cap gen workvolume_det_4cat = 0 if workvolume_det_cat==0
	replace workvolume_det_4cat = 1 if inrange(workvolume_det_cat,1,2)
	replace workvolume_det_4cat = 2 if inrange(workvolume_det_cat,3,4)
	replace workvolume_det_4cat = 3 if inrange(workvolume_det_cat,5,6)
		
	flevelsof workvolume_det_4cat, local(levels)
	foreach i of local levels {
	gen 	byte workvolume_det_4cat`i' = workvolume_det_4cat==`i'
	replace      workvolume_det_4cat`i' = . if workvolume_det_4cat==.			
	}	
	
	global workvolume_det_4cat "workvolume_det_4cat0 workvolume_det_4cat1 workvolume_det_4cat2 workvolume_det_4cat3"

	* Interactions between workvolume_det_4cat and gender
	local workvolume_4cat_gender ""
	foreach temp1 in $workvolume_det_4cat {
		gen byte `temp1'Xgeschlecht = `temp1'*geschlecht 
		local tempname = " `temp1'Xgeschlecht " 
		local workvolume_4cat_gender : list workvolume_4cat_gender | tempname
		
	}
	global workvolume_4cat_gender "`workvolume_4cat_gender'"

	* Generate a part-time dummy
	gen 	byte parttime 	= 0 if workvolume_det_cat==0
	replace parttime		= 1 if inrange(workvolume_det_cat,1,6)
	
	* Interactions between parttime and gender
	gen byte parttimeXgeschlecht = parttime*geschlecht
	
	* Gen dummies for age_cat:
	local val_label : value label alter_cat
	flevelsof alter_cat, local(levels)
	foreach i of local levels {
	gen 	byte alter_cat`i' = alter_cat==`i'
	local lab_`i' : label `val_label' `i'
	label var alter_cat`i' " `lab_`i'' "
	}
	* Age_cat has no missings
		
	* Recode cod_ausbildungsniveau
	recode cod_ausbildungsniveau (.= 999) (198/199 = 999)																	
	cap label drop cod_ausbildung
	cap label define cod_ausbildung	999 "No information"	120 "Primary education"	121 "Lower secondary education" 	130 "Transition between lower and upper sec. Educ."	131 "Upper secondary vocational education (EBA)"	132 "Upper secondary vocational education (EFZ)"	133 "Upper secondary general education (Fachmittelschule)"	134 "Upper secondary general education (Berfusmaturität)"	135 "Upper secondary general education (Frachmaturität)"	136 "Upper secondary general education (Gymnasium)"	150 "Bachelor's or equivalent level, professional (eidg. Fachausweis)"	160 "Bachelor's or equivalent level, professional (eidg. Fachausweis)"	170 "Bachelor's or equivalent level, academic (Fachhochschule)"	171 "Bachelor's or equivalent level, academic (Universität)"	172 "Master's or equivalent level (Fachhochschule)"	 173 "Master's or equivalent level (Universität)"	180 "Doctoral or equivalent level"
	label values cod_ausbildungsniveau cod_ausbildung
	
	local val_label : value label cod_ausbildungsniveau
	flevelsof cod_ausbildungsniveau, local(levels)
	foreach i of local levels {
	gen 	byte cod_ausbildungsniveau`i' = cod_ausbildungsniveau==`i'
	replace      cod_ausbildungsniveau`i' = . if cod_ausbildungsniveau==.			
	local lab_`i' : label `val_label' `i'
	label var cod_ausbildungsniveau`i' " `lab_`i'' "
	}		
	global cod_ausbildungsniveau "cod_ausbildungsniveau120 cod_ausbildungsniveau121 cod_ausbildungsniveau130 cod_ausbildungsniveau131 cod_ausbildungsniveau132 cod_ausbildungsniveau133 cod_ausbildungsniveau134 cod_ausbildungsniveau135 cod_ausbildungsniveau136 cod_ausbildungsniveau150 cod_ausbildungsniveau160 cod_ausbildungsniveau170 cod_ausbildungsniveau171 cod_ausbildungsniveau172 cod_ausbildungsniveau173 cod_ausbildungsniveau180 cod_ausbildungsniveau999"
	
	* Gen isco 1-digit
	recode s_isco_08_2 (10=99) (20=99) (30=99) (50=99) (70=99) (90=99)	
	gen s_isco_08_1 = .
	replace s_isco_08_1 = 1 if inrange(s_isco_08_2,11,14)
	replace s_isco_08_1 = 2 if inrange(s_isco_08_2,21,26)
	replace s_isco_08_1 = 3 if inrange(s_isco_08_2,31,35)
	replace s_isco_08_1 = 4 if inrange(s_isco_08_2,41,44)
	replace s_isco_08_1 = 5 if inrange(s_isco_08_2,51,54)
	replace s_isco_08_1 = 6 if inrange(s_isco_08_2,61,64)
	replace s_isco_08_1 = 7 if inrange(s_isco_08_2,71,75)
	replace s_isco_08_1 = 8 if inrange(s_isco_08_2,81,83)
	replace s_isco_08_1 = 9 if inrange(s_isco_08_2,91,96)
	replace s_isco_08_1 = 0 if inrange(s_isco_08_2,01,03)
	cap label drop isco08_1_lab
	run "Help_files\label_isco08_1.do"
	label values s_isco_08_1 isco08_1_lab
	
	recode s_isco_08_1 (.=0) 		// we recode missing values as zero, otherwise we loose too many observations

	gen 	kanton_s = s_workplace_grossregion
	replace kanton_s = s_candidate_residence if kanton_s==.
	replace kanton_s = . if kanton_s>26
		
	* More globals	
	global workvolume_det_reg "workvolume_det_cat1 workvolume_det_cat2 workvolume_det_cat3 workvolume_det_cat4 workvolume_det_cat5 workvolume_det_cat6 "
	global workvolume_gender_reg "workvolume_det_cat1Xgeschlecht workvolume_det_cat2Xgeschlecht workvolume_det_cat3Xgeschlecht workvolume_det_cat4Xgeschlecht workvolume_det_cat5Xgeschlecht workvolume_det_cat6Xgeschlecht"
	
	global regressors_not_visible "alter_cat1 alter_cat2 alter_cat3 alter_cat4 alter_cat5 registration_to_search versich_verdienst versich_verdienst_zero"
	* Global for not visible regressors without base category for age (alter_cat2)
	global regressors_not_visible_nobase  "alter_cat1  alter_cat3 alter_cat4 alter_cat5 registration_to_search versich_verdienst versich_verdienst_zero"
	
	
	*********************************
	* Analysis with full sample
	*********************************
						
	* First, we estimate the effect of gender on the contact likelihood in the sample of searches where recruiters filtered for candidates looking for a) full-time jobs and b) part-time jobs 		
	* To do this, we only control for the union of the interactions predicting gender and the outcome	
	
	* Keep only interactions in the gender_interact global since we want to keep the other variables anyway in the regression
	local gender_interact $gender_interact
	local subtract $nation_name_kat geschlecht $other_dummy $lang_dummy_full $skills_dummy_full $kanton $occup_dummy $other_contin $squared
	local gender_interact: list gender_interact - subtract
	global gender_interact `gender_interact'
	local words: disp wordcount(" $gender_interact ")
	disp "`words'" 		
	
	tab s_workload,m nol
	gen s_full = 1 if s_workload==10
	gen s_part = 1 if inrange(s_workload,1,9)
	gen s_noworkload = 1 if s_workload==.
	tab s_full,m
	
	foreach i in s_part s_full   {
	local cond "if `i' == 1"
	disp "`cond'"
	quietly reghdfe contact_button_clicked geschlecht  $nation_name_kat $other_dummy $lang_dummy_full $skills_dummy_full $other_contin $squared $gender_interact $rel_rank_cat  $rank $kanton  	`cond'  , absorb(search_tag) vce(cluster tracking_id) 	version(3) 	
	quietly sum contact_button_clicked 			if e(sample)==1
		local mean_disp	: disp %4.2f r(mean)
		local mean		: disp %8.6g r(mean)
		egen no_recr = nvals(tracking_id) 			if e(sample)==1	
		quietly sum no_recr 
		local recr: disp %9.0f r(mean)
		drop no_recr				
			estadd local mean_sample " `mean' "	
			estadd local mean_disp   " `mean_disp' "  
			estadd local no_user_sample " `recr' "	
	eststo `i'_gender
	estimates save "${save_path}\gender_new_`i'" , replace 				
	}	
		
	* Noworkload with gender*parttime interaction
	local cond "if s_noworkload == 1"
	disp "`cond'"
	quietly reghdfe contact_button_clicked geschlecht parttime parttimeXgeschlecht $nation_name_kat $other_dummy $lang_dummy_full $skills_dummy_full $other_contin $squared $gender_interact $rel_rank_cat  $rank $kanton  	`cond'  , absorb(search_tag) vce(cluster tracking_id) 	version(3) 	
	quietly sum contact_button_clicked 			if e(sample)==1
		local mean_disp	: disp %4.2f r(mean)
		local mean		: disp %8.6g r(mean)
		egen no_recr = nvals(tracking_id) 			if e(sample)==1	
		quietly sum no_recr 
		local recr: disp %9.0f r(mean)
		drop no_recr				
			estadd local mean_sample " `mean' "	
			estadd local mean_disp   " `mean_disp' "  
			estadd local no_user_sample " `recr' "	
	eststo s_noworkload_gender
	estimates save "${save_path}\gender_new_s_noworkload_part" , replace 				
	
	* Noworkload without gender*parttime interaction
	local cond "if s_noworkload == 1"
	disp "`cond'"
	quietly reghdfe contact_button_clicked geschlecht parttime  $nation_name_kat $other_dummy $lang_dummy_full $skills_dummy_full $other_contin $squared $gender_interact $rel_rank_cat  $rank $kanton  	`cond'  , absorb(search_tag) vce(cluster tracking_id) 	version(3)	
	quietly sum contact_button_clicked 			if e(sample)==1
		local mean_disp	: disp %4.2f r(mean)
		local mean		: disp %8.6g r(mean)
		egen no_recr = nvals(tracking_id) 			if e(sample)==1	
		quietly sum no_recr 
		local recr: disp %9.0f r(mean)
		drop no_recr				
			estadd local mean_sample " `mean' "	
			estadd local mean_disp   " `mean_disp' "  
			estadd local no_user_sample " `recr' "	
	eststo s_noworkload_gender
	estimates save "${save_path}\gender_new_s_noworkload" , replace	
		
	
	*****************************
	* Baseline estimates with full sample
	* Det. part-time*gender, with lasso selected interactions
	*****************************
	quietly reghdfe contact_button_clicked geschlecht $workvolume_det_reg $workvolume_gender_reg  	$nation_name_kat $other_dummy $lang_dummy_full $skills_dummy_full $other_contin $squared $biglasso_workvolume $rel_rank_cat  $rank $kanton  	$regressors_not_visible_nobase , absorb(search_tag) vce(cluster tracking_id) 	version(3)	
		quietly sum contact_button_clicked 		if e(sample)==1
		local mean_disp	: disp %4.2f r(mean)
		local mean		: disp %8.6g r(mean)
		egen no_recr = nvals(tracking_id) 			if e(sample)==1	
		quietly sum no_recr 
		local recr: disp %9.0f r(mean)
		drop no_recr											
			estadd local mean_sample " `mean' "	
			estadd local mean_disp   " `mean_disp' "  
			estadd local no_user_sample " `recr' "
		eststo workvolume_det_part_out
		estimates save "${save_path}\workvolume_det_interact_all" , replace 	
	
	
	
	*********************************************************************************
	* Effect of different variables on profile click without interactions - placebo test 
	*********************************************************************************	

	* Without nation_kat0
	global nation_name_kat_nobase " nation_kat1 nation_kat2 nation_kat3 nation_kat4 nation_kat5 nation_kat6 nation_kat8 nation_kat9 nation_kat_m name_kat0 name_kat1 name_kat2 name_kat3 name_kat4 name_kat5 name_kat6 name_kat7 name_kat8 name_kat_m"

	* Note: Exclude the base levels of those variables we want to show in the table. Moreover, we use cod_ausbildungsniveau instead of education_isced_
	global other_dummy_nobase "			 erfa_s1 erfa_s2 erfa_s3 erfa_s_m mobility_cat0  			 mobility_cat2 mobility_cat3 mobility_cat4 mobility_cat_m 					 limcontract1 limcontract99 				 verfuegbar1 verfuegbar99 no_searchvar no_diff_prof_m 	zuletzt_s abschluss_s0  			 abschluss_s2 abschluss_s3 abschluss_s_m gesch_kontakt Sonn_Feiertag Schichtarbeit Nachtarbeit Heimarbeit Lehre  		 fuehrer_kat1 fuehrer_kat2 fuehrer_kat3 fuehrer_kat4 fuehrer_kat5 fuehrer_kat6 fuehrer_kat_m cod_ausbildungsniveau120 cod_ausbildungsniveau130 cod_ausbildungsniveau131 cod_ausbildungsniveau132 cod_ausbildungsniveau133 cod_ausbildungsniveau134 cod_ausbildungsniveau135 cod_ausbildungsniveau136 cod_ausbildungsniveau150 cod_ausbildungsniveau160 cod_ausbildungsniveau170 cod_ausbildungsniveau171 cod_ausbildungsniveau172 cod_ausbildungsniveau173 cod_ausbildungsniveau180 cod_ausbildungsniveau999  				 prof_length_2 prof_length_3 prof_length_4 prof_length_99 user_logged_in"

	local cond " if has_skills==0 "
	quietly reghdfe click_candidate geschlecht $workvolume_det_reg 	 $nation_name_kat_nobase $other_dummy_nobase $lang_dummy_full $skills_dummy_full $other_contin $squared 	$regressors_not_visible_nobase		 $rel_rank_cat  $rank $kanton  `cond'	 , absorb(search_tag) vce(cluster tracking_id) 	version(3)
		quietly sum click_candidate 		if e(sample)==1
		local mean_disp	: disp %4.2f r(mean)
		local mean		: disp %8.6g r(mean)
		egen no_recr = nvals(tracking_id) 			if e(sample)==1	
		quietly sum no_recr 
		local recr: disp %9.0f r(mean)
		drop no_recr
			estadd local mean_sample " `mean' "	
			estadd local mean_disp   " `mean_disp' "  
			estadd local no_user_sample " `recr' "
	eststo click_profile_placeb
	estimates save "${save_path}\click_profile_placebo_no_interact" , replace 	
	
		
	****************************************************
	* With person (stes) fixed effects: Focus on people who change their workvolume:
	****************************************************
	
	* With workvolume_det_4cat
	global workvolume_det_4cat_reg "workvolume_det_4cat1 workvolume_det_4cat2 workvolume_det_4cat3" 
	global workvolume_det_4cat_gender_reg "workvolume_det_4cat1Xgeschlecht workvolume_det_4cat2Xgeschlecht workvolume_det_4cat3Xgeschlecht"
		
	set more off
	eststo clear	
	quietly reghdfe contact_button_clicked geschlecht  $workvolume_det_4cat_reg $workvolume_det_4cat_gender_reg  $nation_name_kat $other_dummy $lang_dummy_full $skills_dummy_full $other_contin $squared $biglasso_workvolume $rel_rank_cat  $rank $kanton   , absorb(stes_id) vce(cluster tracking_id) 	version(3)	
		quietly sum contact_button_clicked if e(sample)==1
		local mean_det: disp %12.7g r(mean)
			estadd local mean_sample_det "`mean_det'"
		local mean: disp %9.3f r(mean)
			estadd local mean_sample " `mean' "
		egen no_stes = nvals(stes_id) 		if e(sample)==1	
		quietly sum no_stes 
		local no_stes: disp %9.0f r(mean)
			estadd local no_stes_sample " `no_stes' "	
		drop no_stes		
	estimates store workvolume_all_stesFE
	estimates save "${save_path}\gender_perc_workvolume_4det_biglasso_stesfe_all_together" , replace 
		
		
	*****************************	
	* Now we keep only searches in which the candidate pool has not been restricted to either full- or part-time jobseekers
	*****************************
	
	keep if s_workload==.
			
	*****************************	
	* Only parttime and parttimeXgeschlecht
	*****************************

	quietly reghdfe contact_button_clicked geschlecht parttime  parttimeXgeschlecht   			$nation_name_kat $other_dummy $lang_dummy_full $skills_dummy_full $other_contin $squared $biglasso_workvolume  $regressors_not_visible_nobase   $rel_rank_cat  $rank $kanton 	 , absorb(search_tag) vce(cluster tracking_id) version(3)   
		quietly sum contact_button_clicked 		if e(sample)==1
		local mean_disp	: disp %4.2f r(mean)
		local mean		: disp %8.6g r(mean)
		egen no_recr = nvals(tracking_id) 			if e(sample)==1	
		quietly sum no_recr 
		local recr: disp %9.0f r(mean)
		drop no_recr											
			estadd local mean_sample " `mean' "	
			estadd local mean_disp   " `mean_disp' "  
			estadd local no_user_sample " `recr' "
		eststo part_gender
	estimates save "${save_path}\workvolume_interact_part_dummy_gender" , replace 	
			
	*****************************
	* Only det. part-time  (6 part-time cat), with lasso selected interactions 
	*****************************
	quietly reghdfe contact_button_clicked geschlecht $workvolume_det_reg 							$nation_name_kat $other_dummy $lang_dummy_full $skills_dummy_full $other_contin $squared $biglasso_workvolume  $rel_rank_cat  $rank $kanton  $regressors_not_visible_nobase	 , absorb(search_tag) vce(cluster tracking_id) 	version(3) 
		quietly sum contact_button_clicked 		if e(sample)==1
		local mean_disp	: disp %4.2f r(mean)
		local mean		: disp %8.6g r(mean)
		egen no_recr = nvals(tracking_id) 			if e(sample)==1	
		quietly sum no_recr 
		local recr: disp %9.0f r(mean)
		drop no_recr											
			estadd local mean_sample " `mean' "	
			estadd local mean_disp   " `mean_disp' "  
			estadd local no_user_sample " `recr' "
		eststo workvolume
	estimates save "${save_path}\workvolume_det_only" , replace 	

	*****************************
	* Det. part-time*gender: With lasso selected interactions
	*****************************
	quietly reghdfe contact_button_clicked geschlecht $workvolume_det_reg $workvolume_gender_reg  	$nation_name_kat $other_dummy $lang_dummy_full $skills_dummy_full $other_contin $squared $biglasso_workvolume $rel_rank_cat  $rank $kanton  	$regressors_not_visible_nobase , absorb(search_tag) vce(cluster tracking_id) 	version(3) 
		quietly sum contact_button_clicked 		if e(sample)==1
		local mean_disp	: disp %4.2f r(mean)
		local mean		: disp %8.6g r(mean)
		egen no_recr = nvals(tracking_id) 			if e(sample)==1	
		quietly sum no_recr 
		local recr: disp %9.0f r(mean)
		drop no_recr											
			estadd local mean_sample " `mean' "	
			estadd local mean_disp   " `mean_disp' "  
			estadd local no_user_sample " `recr' "
		eststo workvolume_gender
	estimates save "${save_path}\workvolume_det_interact" , replace 	
		

	*********************************************************************************
	* Only det. part-time: Without interactions - in order to compare workvolume effect with the effects of other variables
	*********************************************************************************	

	* We have to exclude the base levels of those variables we want to show in the table. Moreover, we use cod_ausbildungsniveau instead of education_isced_
	global other_dummy_nobase "			 erfa_s1 erfa_s2 erfa_s3 erfa_s_m mobility_cat0  			 mobility_cat2 mobility_cat3 mobility_cat4 mobility_cat_m 					 limcontract1 limcontract99 				 verfuegbar1 verfuegbar99 no_searchvar no_diff_prof_m 	zuletzt_s abschluss_s0  			 abschluss_s2 abschluss_s3 abschluss_s_m gesch_kontakt Sonn_Feiertag Schichtarbeit Nachtarbeit Heimarbeit Lehre  		 fuehrer_kat1 fuehrer_kat2 fuehrer_kat3 fuehrer_kat4 fuehrer_kat5 fuehrer_kat6 fuehrer_kat_m cod_ausbildungsniveau120 cod_ausbildungsniveau130 cod_ausbildungsniveau131 cod_ausbildungsniveau132 cod_ausbildungsniveau133 cod_ausbildungsniveau134 cod_ausbildungsniveau135 cod_ausbildungsniveau136 cod_ausbildungsniveau150 cod_ausbildungsniveau160 cod_ausbildungsniveau170 cod_ausbildungsniveau171 cod_ausbildungsniveau172 cod_ausbildungsniveau173 cod_ausbildungsniveau180 cod_ausbildungsniveau999  				 prof_length_2 prof_length_3 prof_length_4 prof_length_99 user_logged_in"
	
	* With cod_ausbildungsniveau
	quietly reghdfe contact_button_clicked geschlecht $workvolume_det_reg 			 $nation_name_kat $other_dummy_nobase $lang_dummy_full $skills_dummy_full $other_contin $squared 	$regressors_not_visible_nobase		 $rel_rank_cat  $rank $kanton  	 , absorb(search_tag) vce(cluster tracking_id) 	version(3)  	
		quietly sum contact_button_clicked 		if e(sample)==1
		local mean_disp	: disp %4.2f r(mean)
		local mean		: disp %8.6g r(mean)
		egen no_recr = nvals(tracking_id) 			if e(sample)==1	
		quietly sum no_recr 
		local recr: disp %9.0f r(mean)
		drop no_recr											
			estadd local mean_sample " `mean' "	
			estadd local mean_disp   " `mean_disp' "  
			estadd local no_user_sample " `recr' "
		eststo workv_gender_noint
	estimates save "${save_path}\only_workvolume_det_no_interact" , replace 	
		
	*****************************
	* Robustness: Only those without skills
	*****************************
	
	local cond " if has_skills==0 "
	disp "`cond'"
	quietly reghdfe contact_button_clicked geschlecht $workvolume_det_reg $workvolume_gender_reg $nation_name_kat $other_dummy $lang_dummy_full $skills_dummy_full $other_contin $squared $biglasso_workvolume  $rel_rank_cat  $rank $kanton  $regressors_not_visible_nobase  	`cond' , absorb(search_tag) vce(cluster tracking_id) 	version(3) 
		quietly sum contact_button_clicked 		if e(sample)==1
		local mean_disp	: disp %4.2f r(mean)
		local mean		: disp %8.6g r(mean)
		egen no_recr = nvals(tracking_id) 			if e(sample)==1	
		quietly sum no_recr 
		local recr: disp %9.0f r(mean)
		drop no_recr											
			estadd local mean_sample " `mean' "	
			estadd local mean_disp   " `mean_disp' "  
			estadd local no_user_sample " `recr' "
		eststo workvolume_no_skills
		estimates save "${save_path}\workvolume_det_gender_interact_no_skills" , replace 	

		
	*********************************************************************************
	* Robustness: With occupation FE instead of search fixed effects
	*********************************************************************************	
	
	quietly reghdfe contact_button_clicked geschlecht $workvolume_det_reg $workvolume_gender_reg  $nation_name_kat $other_dummy $lang_dummy_full $skills_dummy_full $other_contin $squared 	$biglasso_workvolume  $regressors_not_visible_nobase	 $rel_rank_cat  $rank $kanton  	 , absorb(s_bn2000_5) vce(cluster tracking_id) 	version(3) 
		quietly sum contact_button_clicked 		if e(sample)==1
		local mean_disp	: disp %4.2f r(mean)
		local mean		: disp %8.6g r(mean)
		egen no_recr = nvals(tracking_id) 			if e(sample)==1	
		quietly sum no_recr 
		local recr: disp %9.0f r(mean)
		drop no_recr											
			estadd local mean_sample " `mean' "	
			estadd local mean_disp   " `mean_disp' "  
			estadd local no_user_sample " `recr' "
	eststo workvolume_det_occupFE
	estimates save "${save_path}\workvolume_det_interact_occupFE" , replace 	
		
	*********************************************	
	* Estimate part-time*gender effect by kanton_s with interactions
	*********************************************	
	
	gen 	kanton_s = s_workplace_grossregion
	replace kanton_s = s_candidate_residence if kanton_s==.
	replace kanton_s = . if kanton_s>26
	
	tab kanton_s,m				// 47% of the observations missing
	
	tab kanton_s if rank==1,m	// 38% of the searches specify neither firm location nor residency of the jobseeker
	
	* Save mean contact rate per canton
	levelsof kanton_s, local(levels)
	foreach i of local levels {
	eststo clear
	local cond " if kanton_s==`i'"
	di "`i'"
		quietly estpost sum contact_button_clicked `cond' 
		eststo summary_kanton_s`i'	
		estimates save "${save_path}\summary_kanton_s`i'" , replace 
	}
			
	local kant_workv_geschl ""
	levelsof kanton_s, local(levels)
	foreach i of local levels {
		gen kanton_s_`i' = kanton_s==`i'
		gen kanton_s_`i'Xgeschlecht 				= kanton_s_`i'*geschlecht
		gen kanton_s_`i'Xparttime 					= kanton_s_`i'*parttime
		gen kanton_s_`i'XparttimeXgeschlecht 		= kanton_s_`i'*parttimeXgeschlecht
		local varnames "kanton_s_`i'Xgeschlecht kanton_s_`i'Xparttime kanton_s_`i'XparttimeXgeschlecht"
		local kant_workv_geschl: list kant_workv_geschl | varnames
	}
	global kant_workv_geschl "`kant_workv_geschl'"
	di "$kant_workv_geschl"
				
	quietly reghdfe contact_button_clicked  $kant_workv_geschl $nation_name_kat $other_dummy $lang_dummy_full $skills_dummy_full $other_contin $squared $biglasso_workvolume  $regressors_not_visible_nobase   $rel_rank_cat  $rank $kanton  	`cond'	 , absorb(search_tag) vce(cluster tracking_id) 	version(3) 	
		quietly sum contact_button_clicked 		if e(sample)==1
		local mean_disp	: disp %4.2f r(mean)
		local mean		: disp %8.6g r(mean)
		egen no_recr = nvals(tracking_id) 			if e(sample)==1	
		quietly sum no_recr 
		local recr: disp %9.0f r(mean)
		drop no_recr											
			estadd local mean_sample " `mean' "	
			estadd local mean_disp   " `mean_disp' "  
			estadd local no_user_sample " `recr' "
	eststo kant_int
	estimates save "${save_path}\workvolume_by_kant_int" , replace 
	

	*********************************************	
	* Estimate part-time*gender effect by yes share in parental leave referendum in canton
	*********************************************	
	
	merge m:1 kanton_s using "Misc_files\abstimmung_vaterschaft.dta"
	drop _merge
					
	* Generate dummy if canton has above-average yes-vote share:
	bys kanton_s: gen n_cant = _n 
	
	gen yes_vote = 1-no_share
	sum yes_vote if n_cant==1
	disp r(mean)		
	gen byte high_yes = yes_vote>r(mean) & yes_vote<.
	replace  high_yes = . if yes_vote==. 
	tab high_yes,m	
	
	gen byte parttimeXhigh_yes = parttime* high_yes
	gen byte parttimeXgeschlechtXhigh_yes = parttimeXgeschlecht * high_yes	
	gen byte geschlechtXhigh_yes = geschlecht * high_yes

	quietly reghdfe contact_button_clicked   parttime geschlecht  		 geschlechtXhigh_yes 	parttimeXgeschlecht parttimeXhigh_yes 	parttimeXgeschlechtXhigh_yes $nation_name_kat $other_dummy $lang_dummy_full $skills_dummy_full $other_contin $squared $biglasso_workvolume  $regressors_not_visible_nobase   $rel_rank_cat  $rank $kanton  	`cond'	 , absorb(search_tag) vce(cluster tracking_id) 	version(3) 	
	quietly sum contact_button_clicked 		if e(sample)==1
		local mean_disp	: disp %4.2f r(mean)
		local mean		: disp %8.6g r(mean)
		egen no_recr = nvals(tracking_id) 			if e(sample)==1	
		quietly sum no_recr 
		local recr: disp %9.0f r(mean)
		drop no_recr											
			estadd local mean_sample " `mean' "	
			estadd local mean_disp   " `mean_disp' "  
			estadd local no_user_sample " `recr' "
	eststo hyes_share_int
	estimates save "${save_path}\parttime_high_yes_share_parental_leave_int" , replace 	
	

	
	*********************************************
	* By gender typicality of recruiter selection behavior
	*********************************************	
	
	* Merge the share of female workers per occupation from LSE (2016) to the sample
	merge m:1 s_isco_08_2  using "Misc_files\lse_isco_women.dta"
	* Those not merged are missing
	drop if _merge==2
	drop _merge 
		
	gen			fem_share_isco2_cat_40 = 1 if woman<0.40
	replace		fem_share_isco2_cat_40 = 2 if inrange(woman,0.40,0.60) 	& woman<.	
	replace		fem_share_isco2_cat_40 = 3 if woman>0.60 	& woman<.
	tab fem_share_isco2_cat_40,m	
	
	* Define gender typicality by share of gender typical profile views and share of gender typical candidates in result list
	
	gen in_list = 1
	
	foreach t in  click list {
	if "`t'" == "click" {
		local outcome "click_candidate"
	}	
	else	if "`t'" == "list" {
		local outcome "in_list"
	}	
	cap drop typical_`t'2
	gen 		typical_`t'2 = 			`outcome'==1 & geschlecht==0 & fem_share_isco2_cat_40==1
	replace		typical_`t'2 = 1 if 	`outcome'==1 & geschlecht==1 & fem_share_isco2_cat_40==3
	replace 	typical_`t'2 = . if fem_share_isco2_cat_40==2 | `outcome'==0 | fem_share_isco2_cat_40==.
	 
	tab typical_`t'2 ,m
	tab geschlecht fem_share_isco2_cat_40 if typical_`t'2==0,m
	tab geschlecht fem_share_isco2_cat_40 if typical_`t'2==1,m	
	
	bys tracking_id: egen share_typical_`t'2 	= mean(typical_`t'2)
	bys tracking_id: egen n_typical_`t'2		= count(typical_`t'2)
	}
	
	* Only if there are more than 10 profile clicks  in occupations with more than 60% men or women (i.e. n_typical_contact2>=10)
	* Only if there are at least 5% non-typical candidates on the list
	
	cap drop gender_typ_recruiter_click2
	gen gender_typ_recruiter_click2 = share_typical_list2 <  share_typical_click2 if share_typical_list2<0.95 & n_typical_click2>=10
	tab gender_typ_recruiter_click2,m
	
	* Gen interactions for regression	
	gen geschlechtXgender_typ2_cl 			= geschlecht*gender_typ_recruiter_click2
	gen parttimeXgender_typ2_cl 			= parttime*gender_typ_recruiter_click2
	gen partXgeschlechtXgender_typ2_cl 		= parttimeXgeschlecht*gender_typ_recruiter_click2
	
	quietly reghdfe contact_button_clicked   parttime geschlecht gender_typ_recruiter_click2 geschlechtXgender_typ2_cl 	parttimeXgeschlecht parttimeXgender_typ2_cl 	partXgeschlechtXgender_typ2_cl $nation_name_kat $other_dummy $lang_dummy_full $skills_dummy_full $other_contin $squared $biglasso_workvolume  $regressors_not_visible_nobase   $rel_rank_cat  $rank $kanton  	`cond'	 , absorb(search_tag) vce(cluster tracking_id) 	version(3) 	
		quietly sum contact_button_clicked 		if e(sample)==1
		local mean_disp	: disp %4.2f r(mean)
		local mean		: disp %8.6g r(mean)
		egen no_recr = nvals(tracking_id) 			if e(sample)==1	
		quietly sum no_recr 
		local recr: disp %9.0f r(mean)
		drop no_recr											
			estadd local mean_sample " `mean' "	
			estadd local mean_disp   " `mean_disp' "  
			estadd local no_user_sample " `recr' "
	eststo typ_recr_int2_cl
	estimates save "${save_path}\parttime_gender_typical_recruiter2_clicks_int" , replace 
	
	
	*********************************************	
	* Estimate part-time*gender effect by isco_1 with interactions
	*********************************************	
	
	local isco1_part_geschl ""
	levelsof s_isco_08_1, local(levels)
	foreach i of local levels {
		cap gen isco1_`i' = s_isco_08_1==`i'
		cap gen isco1_`i'Xgeschlecht 				= isco1_`i'*geschlecht
		gen isco1_`i'Xparttime 					= isco1_`i'*parttime
		gen isco1_`i'XparttimeXgeschlecht 		= isco1_`i'*parttimeXgeschlecht
		local varnames "isco1_`i'Xgeschlecht isco1_`i'Xparttime isco1_`i'XparttimeXgeschlecht"
		local isco1_part_geschl: list isco1_part_geschl | varnames
	}
	global isco1_part_geschl "`isco1_part_geschl'"
	di "$isco1_part_geschl"
		
	quietly reghdfe contact_button_clicked  $isco1_part_geschl $nation_name_kat $other_dummy $lang_dummy_full $skills_dummy_full $other_contin $squared $biglasso_workvolume  $regressors_not_visible_nobase   $rel_rank_cat  $rank $kanton  	`cond'	 , absorb(search_tag) vce(cluster tracking_id) 	version(3) 	
		quietly sum contact_button_clicked 		if e(sample)==1
		local mean_disp	: disp %4.2f r(mean)
		local mean		: disp %8.6g r(mean)
		egen no_recr = nvals(tracking_id) 			if e(sample)==1	
		quietly sum no_recr 
		local recr: disp %9.0f r(mean)
		drop no_recr											
			estadd local mean_sample " `mean' "	
			estadd local mean_disp   " `mean_disp' "  
			estadd local no_user_sample " `recr' "
	eststo isco1_part_int
	estimates save "${save_path}\parttime_gender_by_isco1_int" , replace 	
	
	
	*********************************************	
	* Estimate part-time*gender effect by isco_2 with interactions
	*********************************************	
	
	* Save occupation specific mean and number of observations per occupation
	
	recode s_isco_08_2 (.=999)
	
	levelsof s_isco_08_2, local(levels)
	foreach i of local levels {
	eststo clear
	local cond " if s_isco_08_2==`i'"
	di "`i'"
		quietly estpost sum contact_button_clicked `cond' 
		eststo summary_isco`i'	
		estimates save "${save_path}\summary_isco`i'" , replace 
	}
	
	local isco2_workv_geschl ""
	levelsof s_isco_08_2, local(levels)
	foreach i of local levels {
		gen isco2_`i' = s_isco_08_2==`i'
		gen isco2_`i'Xgeschlecht 				= isco2_`i'*geschlecht
		gen isco2_`i'Xparttime 					= isco2_`i'*parttime
		gen isco2_`i'XparttimeXgeschlecht 		= isco2_`i'*parttimeXgeschlecht
		local varnames "isco2_`i'Xgeschlecht isco2_`i'Xparttime isco2_`i'XparttimeXgeschlecht"
		local isco2_workv_geschl: list isco2_workv_geschl | varnames
	}
	global isco2_workv_geschl "`isco2_workv_geschl'"
	di "$isco2_workv_geschl"
				
	quietly reghdfe contact_button_clicked  $isco2_workv_geschl $nation_name_kat $other_dummy $lang_dummy_full $skills_dummy_full $other_contin $squared $biglasso_workvolume  $regressors_not_visible_nobase   $rel_rank_cat  $rank $kanton  	`cond'	 , absorb(search_tag) vce(cluster tracking_id) 	version(3) 
		quietly sum contact_button_clicked 		if e(sample)==1
		local mean_disp	: disp %4.2f r(mean)
		local mean		: disp %8.6g r(mean)
		egen no_recr = nvals(tracking_id) 			if e(sample)==1	
		quietly sum no_recr 
		local recr: disp %9.0f r(mean)
		drop no_recr											
			estadd local mean_sample " `mean' "	
			estadd local mean_disp   " `mean_disp' "  
			estadd local no_user_sample " `recr' "
	eststo isco2_int
	estimates save "${save_path}\workvolume_by_isco2_int" , replace 
	
	
	*********************************************	
	* Estimate only part-time effect by isco_2 with interactions
	*********************************************	
		
	local isco2_workv ""
	levelsof s_isco_08_2, local(levels)
	foreach i of local levels {
		local varnames "isco2_`i'Xparttime"
		local isco2_workv: list isco2_workv | varnames
	}
	global isco2_workv "`isco2_workv'"
	di "$isco2_workv"
				
	quietly reghdfe contact_button_clicked  geschlecht  $isco2_workv $nation_name_kat $other_dummy $lang_dummy_full $skills_dummy_full $other_contin $squared $biglasso_workvolume  $regressors_not_visible_nobase   $rel_rank_cat  $rank $kanton  	`cond'	 , absorb(search_tag) vce(cluster tracking_id) 	version(3) 	
		quietly sum contact_button_clicked 		if e(sample)==1
		local mean_disp	: disp %4.2f r(mean)
		local mean		: disp %8.6g r(mean)
		egen no_recr = nvals(tracking_id) 			if e(sample)==1	
		quietly sum no_recr 
		local recr: disp %9.0f r(mean)
		drop no_recr											
			estadd local mean_sample " `mean' "	
			estadd local mean_disp   " `mean_disp' "  
			estadd local no_user_sample " `recr' "
	eststo isco2_int
	estimates save "${save_path}\only_parttime_by_isco2_int" , replace 
	